//-------------------------------------------------------------------------------------------------------
//      Copyright (c) 2005-2007, Be Nanashi-San 
// 
//      Permission is hereby granted, free of charge, to any person obtaining a 
//      copy of this software and associated documentation files (the "Software"), 
//      to deal in the Software without restriction, including without limitation 
//      the rights to use, copy, modify, merge, publish, distribute, sublicense, 
//      and/or sell copies of the Software, and to permit persons to whom the 
//      Software is furnished to do so, subject to the following conditions: 
// 
//      The above copyright notice and this permission notice shall be included in 
//      all copies or substantial portions of the Software. 
// 
//      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
//      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
//      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
//      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
//      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
//      FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
//      DEALINGS IN THE SOFTWARE. 
// 
//      File Name:   	MSticker.cpp
//      Author:      	Be Nanashi-San
//
//		Description:	
//-------------------------------------------------------------------------------------------------------
#include <Message.h>
#include <Messenger.h>
#include <Screen.h>
#include "K2chTipTextView.h"
#include "MSticker.h"


////////////////////////////////////////////////////////////////////////////////
// MBackGrounds
//
//
////////////////////////////////////////////////////////////////////////////////
MBackGrounds::MBackGrounds(BRect frame, const char *name, uint32 resizingMode, uint32 flags)
: BView(frame, name, resizingMode, flags|B_FULL_UPDATE_ON_RESIZE)
{
		SetViewColor(B_TRANSPARENT_COLOR);
}
////////////////////////////////////////////////////////////////////////////////
// MBackGrounds
//
//
////////////////////////////////////////////////////////////////////////////////
void
MBackGrounds::Draw(BRect /*updtRect*/)
{
	const uint8 data[] = {250, 247, 238, 229, 210, 200 };
	SetDrawingMode(B_OP_MIN);
	BRect frame(Bounds());
	for (int32 i = 0; i < 6; i++) {
		BView::SetHighColor(data[i], data[i], data[i], 198);
		BView::StrokeRoundRect(frame, 6 - i, 6 - i);
		frame.InsetBy(1, 1);
	}
	frame.InsetBy(-1, -1);
	frame.SetLeftTop(BPoint(0, 0));
	BView::SetDrawingMode(B_OP_COPY);
	BView::StrokeRect(frame);
}

////////////////////////////////////////////////////////////////////////////////
// MSticker
//
//
////////////////////////////////////////////////////////////////////////////////
MSticker::MSticker(BRect frame, K2chTipTextView *fView)
	: BWindow(frame, "TipWindow", B_NO_BORDER_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, 0)
{
	if (!fView)	return;
	
	BWindow::ResizeBy(7, 7);
	MBackGrounds *backView = new MBackGrounds(Bounds(), "MSticker:backgrounds", B_FOLLOW_ALL, B_WILL_DRAW);
	fView->MoveTo(1, 1);
	backView->AddChild(fView);
	this->AddChild(backView);
	fTextView = fView;
}

////////////////////////////////////////////////////////////////////////////////
// MessageReceived
//
//
////////////////////////////////////////////////////////////////////////////////
void
MSticker::MessageReceived(BMessage *msg)
{
	switch (msg->what) {
	case kMSG_MOUSE_DOWN_MOVE:
		break;

	case kMSG_EXITED_VIEW:
	case kMSG_MOUSE_UP:
		BWindow::Hide();
		break;

	default:
		BWindow::MessageReceived(msg);
	}
}
////////////////////////////////////////////////////////////////////////////////
// Show
//
//
////////////////////////////////////////////////////////////////////////////////
void
MSticker::ShowSticker(BPoint point)
{
	BRect scrRect = BScreen().Frame();
	BWindow::MoveTo(point.x, point.y - (Frame().Height() - 32));
	if (!scrRect.Contains(Frame())) {
		/* 未実装 */
	}
	BWindow::Show();
}
